package com.ruoyi.business.controller.market;

import com.ruoyi.base.controller.BaseController;
import com.ruoyi.base.pojo.HttpResult;
import com.ruoyi.base.utils.inputcheck.InputCheckUtils;
import com.ruoyi.business.enums.market.MarketTypeEnum;
import com.ruoyi.business.pojo.market.MarketCacheDTO;
import com.ruoyi.business.pojo.market.MarketCacheQuery;
import com.ruoyi.business.service.market.MarketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 市场
 *
 * @author Administrator
 */
@Slf4j
@Api(tags = "市场")
@RestController
@RequestMapping("/market")
public class MarketController extends BaseController {
    @Autowired
    private MarketService marketService;

    /**
     * 发布
     */
    @ApiOperation("发布")
    @PostMapping("/publish")
    public HttpResult<String> publish(MarketCacheQuery query, @ApiParam("1买2卖") int type) {
        InputCheckUtils.checkStr(query.getTitle(), "请输入标题");
        InputCheckUtils.checkStr(query.getContent(), "请输入内容");
        InputCheckUtils.checkStr(query.getNickName(), "请输入发布人");
        InputCheckUtils.checkStr(query.getCode(), "游戏编号");
        InputCheckUtils.checkStr(query.getGalaxy(), "请输入所在星系");

        marketService.publish(query, MarketTypeEnum.ofCode(type));
        return success();
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @DeleteMapping("/del")
    public HttpResult<String> del(@ApiParam("id") String id, @ApiParam("1买2卖") int type) {
        marketService.del(id, MarketTypeEnum.ofCode(type));
        return success();
    }

    /**
     * 查看列表
     */
    @ApiOperation("查看列表")
    @GetMapping("/list")
    public HttpResult<List<MarketCacheDTO>> getList(@ApiParam("关键词") String keyword,
                                                    @ApiParam("星系") String galaxy,
                                                    @ApiParam("发布人") String nickName,
                                                    @ApiParam("1买2卖") int type) {
        return data(marketService.getList(keyword, galaxy, nickName, MarketTypeEnum.ofCode(type)));
    }

    /**
     * 查看详情
     */
    @ApiOperation("查看详情")
    @GetMapping("/detail")
    public HttpResult<MarketCacheDTO> getDetail(@ApiParam("id") String id,
                                                @ApiParam("1买2卖") int type) {
        return data(marketService.getDetail(id, MarketTypeEnum.ofCode(type)));
    }
}
